﻿using System;
using IotS.Core.Helpers;
using Microsoft.Extensions.Configuration;

namespace IotS.MessageService
{
    class Program
    {
        public static IConfigurationRoot Configuration { get; private set; }

        static void Main(string[] args)
        {
            //Console.WriteLine("Press to start...");
            //Console.ReadKey();
            var builder = new ConfigurationBuilder();
            builder.SetBasePath(AppContext.BaseDirectory)
                .AddJsonFile("appsettings.json", true, true)
                .AddEnvironmentVariables();
            Configuration = builder.Build();
            ConfigHelper.Set(Configuration);

            IService service;

            if (args.Length == 0 || args[0].ToLower() == "sender")
            {
                service = new MessageHandler();
            }
            else if (args.Length > 0 || args[0].ToLower() == "listenr")
            {
                service = new MessageListener();
            }
            else
            {
                throw new ArgumentException("start with \"sender\"(empty) or \"listener\"");
            }

            service.Start();

            while (true)
            {
                
            }

            service.Dispose();
        }
    }
}
